//package com.zj.weather.bgviews;
//
//import android.content.Context;
//import android.graphics.Canvas;
//import android.graphics.drawable.Drawable;
//
//
//import java.util.ArrayList;
//import java.util.List;
//
//import com.zj.weather.R;
//import com.zj.weather.base.BaseWeatherBgView;
//
//import static com.zj.weather.utils.RandomUtils.fixAlpha;
//import static com.zj.weather.utils.RandomUtils.getRandom;
//
///**
// * Created by zhaojie on 2017/9/14.
// */
//public class OverCastDrawer extends BaseWeatherBgView {
//
//    private List<CloudHolder> cloudHolders = new ArrayList<>();
//    private static final int count = 2;
//    private Context context;
//
//    public OverCastDrawer(Context context, int key) {
//        super(context, key);
//    }
//
//    private boolean isRight = false;
//
//    @Override
//    public void setSize(int width, int height) {
//        super.setSize(width, height);
//        if (cloudHolders.size() == 0) for (int i = 0; i < count; i++) {
//            Drawable cloud = context.getResources().getDrawable(R.mipmap.overcast);
//            cloudHolders.add(new CloudHolder(isRight, cloud, 0.0003f, width, width * 1.7f, 1.0f, true));
//            isRight = !isRight;
//        }
//    }
//
//    @Override
//    protected void initValues(Context context) {
//        this.context = context;
//    }
//
//    @Override
//    public void drawWeather(Canvas canvas, float alpha) {
//        for (CloudHolder holder : cloudHolders)
//            holder.updateAndDraw(canvas, alpha);
//    }
//
//    public static class CloudHolder {
//        private final Drawable drawable;
//        private final float percentWidthPerframe;
//        private final float screenWidth;
//        private final float drawableWidth, drawableHeight;
//        private float curX;
//        private final float minX, maxX;
//        private final float maxAlpha;
//        private final boolean canLoop;
//        private boolean isPost = true;
//
//        CloudHolder(boolean isRight, Drawable drawable, float percentWidthPerframe, float screenWidth, float drawableWidth, float maxAlpha, final boolean canLoop) {
//            this.drawable = drawable;
//            this.percentWidthPerframe = percentWidthPerframe;
//            this.screenWidth = screenWidth;
//            if (drawableWidth < screenWidth) {
//                drawableWidth = screenWidth * 1.1f;
//            }
//            float scale = isRight ? 0.401f : 0.353f;
//            this.drawableWidth = drawableWidth;
//            this.drawableHeight = drawableWidth * scale;
//            minX = this.screenWidth - this.drawableWidth;
//            maxX = 0f;
//            this.curX = isRight ? 0 : minX;
//            this.maxAlpha = maxAlpha;
//            this.canLoop = canLoop;
//        }
//
//        void updateAndDraw(Canvas canvas, float alpha) {
//            float curOffset = percentWidthPerframe * drawableWidth * getRandom(0.5f, 1);
//            if (isPost) {
//                curX -= curOffset;
//                if (curX < minX) {
//                    isPost = false;
//                }
//            } else {
//                curX += curOffset;
//                if (curX >= maxX) {
//                    isPost = true;
//                }
//            }
//            float curAlpha = 1f;
//            if (!canLoop) {
//                float percent = Math.abs(curX / minX);
//                curAlpha = (percent > 0.5f) ? ((1 - percent) / 0.5f) : (percent / 0.5f);
//                curAlpha = fixAlpha(curAlpha) * maxAlpha;
//            }
//            drawable.setAlpha(Math.round(alpha * 255f * curAlpha));
//            final int left = Math.round(curX);
//            drawable.setBounds(left, -(int) (drawableHeight / 2f), Math.round(left + drawableWidth), Math.round(drawableHeight));
//            drawable.draw(canvas);
//        }
//    }
//}
//
